package mutsumimod.powers;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.FontHelper;
import com.megacrit.cardcrawl.powers.AbstractPower;
import mutsumimod.MutsumiMod;
import mutsumimod.character.Mutsumi;
import mutsumimod.monitors.PantheonizedHeroMonitor;
import mutsumimod.monitors.SakiDownMonitor;

public class StandPower extends BasePower {
    public static final String POWER_ID = MutsumiMod.makeID(StandPower.class.getSimpleName());

    public StandPower(AbstractCreature owner, int amount) {
        super(POWER_ID, PowerType.BUFF, false, owner, amount);
    }

    @Override
    public void updateDescription() {
        this.description = DESCRIPTIONS[0] + this.amount + DESCRIPTIONS[1];
    }

    @Override
    public void renderAmount(SpriteBatch sb, float x, float y, Color c) {
        if (this.amount < 0) {
            return;
        }
        if (!this.isTurnBased) {
            this.greenColor2.a = c.a;
            c = this.greenColor2;
        }
        FontHelper.renderFontRightTopAligned(sb, FontHelper.powerAmountFont,
                Integer.toString(this.amount), x, y, this.fontScale, c);

    }

    @Override
    public void stackPower(int stackAmount) {
        int preAmount = this.amount;
        super.stackPower(stackAmount);
        if (this.amount > 10) {
            this.amount = 10;
        }
        if(amount==10){
            PantheonizedHeroMonitor.putPantheonizedHeroInHand();
        }
        for (AbstractPower power: this.owner.powers) {
            if (power instanceof BasePower) {
                ((BasePower) power).onChangeStandAmount(this.amount - preAmount);
            }
        }

        AbstractPlayer p = AbstractDungeon.player;
        if (!(p instanceof Mutsumi)) {
            return;
        }
        if (!((Mutsumi) p).isMortis && this.amount > 5) {
            ((Mutsumi) p).changeStand(true);
        }
    }

    //stand移除时也用ReducePowerAction，因为要触发这里的钩子
    @Override
    public void reducePower(int reduceAmount) {
        int preAmount = this.amount;
        super.reducePower(reduceAmount);
        for (AbstractPower power: this.owner.powers) {
            if (power instanceof BasePower) {
                ((BasePower) power).onChangeStandAmount(preAmount - this.amount);
            }
        }
        SakiDownMonitor.addStandReduceAmount(amount);
        for (AbstractPower power: this.owner.powers) {
            if (power instanceof BasePower) {
                ((BasePower) power).onLoseStand(preAmount - this.amount);
            }
        }
        AbstractPlayer p = AbstractDungeon.player;
        if (!(p instanceof Mutsumi)) {
            return;
        }
        if (((Mutsumi) p).isMortis && this.amount <= 5) {
            ((Mutsumi) p).changeStand(false);
        }
    }

    @Override
    public void onRemove(){
        int preAmount = this.amount;
        super.onRemove();
        for (AbstractPower power: this.owner.powers) {
            if (power instanceof BasePower) {
                ((BasePower) power).onChangeStandAmount(preAmount);
            }
        }
        SakiDownMonitor.addStandReduceAmount(amount);
        for (AbstractPower power: this.owner.powers) {
            if (power instanceof BasePower) {
                ((BasePower) power).onLoseStand(preAmount);
            }
        }
    }


}
